#include "FPCH.h"

#include "FMetrics.h"

namespace Font
{

	Metrics::Metrics(Library* a_Library, Loader* a_Loader, Family* a_Family)
	{
		m_Library = a_Library;

		m_Loader = a_Loader;
		m_Family = a_Family;

		m_Owner = NULL;

		m_RangeStart = m_RangeEnd = 0;
	}

	Metrics::~Metrics()
	{
		
	}

	bool Metrics::CheckMatchStyle(unsigned int a_Style)
	{
		return ((m_Style & a_Style) == a_Style);
	}

	unsigned int Metrics::GetRangeStart()
	{
		return m_RangeStart;
	}

	unsigned int Metrics::GetRangeEnd()
	{
		return m_RangeEnd;
	}

	Family* Metrics::GetFamily()
	{
		return m_Family;
	}

	void Metrics::SetFace(Face* a_Face)
	{
		m_Owner = a_Face;
	}

	Face* Metrics::GetFace()
	{
		return m_Owner;
	}

	FaceHandle* Metrics::CreateFont(unsigned int a_Size, unsigned int a_LineHeight)
	{
		std::map<unsigned int, FaceHandle*>::iterator found = m_HandlesBySize.find(a_Size);
		if (found != m_HandlesBySize.end())
		{
			return found->second;
		}

		FaceHandle* result = new FaceHandle(m_Library, m_Family);
		result->SetMetrics(this);
		result->SetFontSize(a_Size, a_LineHeight);

		m_Handles.push_back(result);
		m_HandlesBySize.insert(std::pair<int, FaceHandle*>(a_Size, result));

		return result;
	}

}; // namespace Font